/*******************************************************************************
 * Copyright (c) 2015 by jalen Corporation all right reserved.
 * 2015年5月14日 
 *
 *******************************************************************************/
package com.cqc.customdialog01;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


public class ProgressDialogUtil2 {
    private static ProgressDialogUtil2 instance = null;
    private static Dialog dialog;
    private static View view;
    private TextView tv;

    public synchronized static ProgressDialogUtil2 getInstance(Context context) {

        if (instance == null) {
            instance = new ProgressDialogUtil2();
            dialog = new Dialog(context, R.style.CustomDialogStyle);
            view = LayoutInflater.from(context).inflate(R.layout.custom_progress_dialog_1, null);
            dialog.setContentView(view);

            ImageView progressImageView = (ImageView) view.findViewById(R.id.iv_loading);
            AnimationDrawable animationDrawable = (AnimationDrawable) progressImageView.getDrawable();
            animationDrawable.start();

            //要放在动画后面,否则无效
            dialog.setCanceledOnTouchOutside(false);
        }
        return instance;
    }

    public void show() {
        dialog.show();
    }

    public void showstr(String str) {
        if (tv == null) {
            tv = (TextView) view.findViewById(R.id.tv_loading);
            tv.setText(str);
        } else {
            tv.setText(str);
        }
        dialog.show();
    }

    public void cancle() {
        if (dialog == null) {
            return;
        } else {
            dialog.cancel();
        }
    }
}
